package controllers

import (
	"crypto/md5"
	"encoding/hex"
	"math/rand"
	"strings"
	"time"
	models "yun/Models"
)

type ApiBaseController struct {
}

var db = models.DB

// md5加密
func (a ApiBaseController) encryptMD5(text string) string {
	hash := md5.Sum([]byte(text))
	return hex.EncodeToString(hash[:])
}

// 随机字母数字串
func (a ApiBaseController) generateRandomString(length int) string {
	rand.Seed(time.Now().UnixNano())
	chars := []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
	var b strings.Builder
	for i := 0; i < length; i++ {
		b.WriteRune(chars[rand.Intn(len(chars))])
	}
	return b.String()
}
